package Filter;

import Utils.DBHelp;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class javaWebFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        try {
            filterChain.doFilter(servletRequest, servletResponse);
            DBHelp.Commit();
        } catch (Exception e) {
            DBHelp.rollback();
            throw new RuntimeException(e);
            //为了抛出异常给tomcat
            //根据错误页面来显示错误页面
            //异常可以参与业务逻辑
        }
    }
    @Override
    public void destroy() {

    }
}
